<template>
  <div class="card-page">
    <tool-bar nav="" :title='action_name + "sso应用配置"'>
      <el-button size="small" @click="$router.push('/system/sso-config/add')" v-if="$props.action=='edit'">新建</el-button>
      <el-button size="small" @click="save_click" type="primary"> 保存</el-button>
    </tool-bar>
    <el-row :gutter="12" type="flex">
      <el-col :span="12">
        <el-card shadow="always">
            <template #header> <span>基本信息</span> </template>
          <kv label="应用名称">
            <el-input v-model="info.name" chk="*" />
          </kv>
          <kv label="应用ID"  chk="*">
            <el-input v-model="info.appId" />
          </kv>
          <kv label="应用秘钥">
            <el-input v-model="info.id" disabled/>
          </kv>
          <kv label="应用主页">
            <el-input v-model="info.homepageUrl"    />
          </kv>
<!--          <kv label="应用Host">
            <el-input v-model="info.host" />
          </kv>-->
          <kv label="描述">
            <el-input   type="textarea" v-model="info.remark" />
          </kv>

        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="always">

        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
/**
 * Created by CodeGenerator  at 2021-04-06 17:04:42
 */
import RefCorp from "../../home/empty-ref.vue"




//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({"info":{"corp":{}}});
const info = $computed(()=> $data.info );

const $props = defineProps({
    action: { type: String } ,
    id : { type: String }
});


const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);

const action = $computed( function() {
    return $props.id ? "edit" : "add";
});
const action_name = $computed( function() {
    return {add: "添加", edit: "修改"}[$props.action]
});

const loadData = function() {
    if (!$props.id) return;
    jv.$http.post("/system/sso-config/detail/" + $props.id).then(res => {
        $data.info = res.data.data;
    });
};
const save_click = function() {
//校验
    if (jv.chk_main() == false) {
        return;
    }
    jv.$http.post("/system/sso-config/save", $data.info).then(res => {
//[axios拦截器中已处理了异常]。
        jv.info(action_name + " 成功");
        if ($props.action == "add") {
            jv.$router.push("/system/sso-config/edit/" + res.data.data)
        } else if ($props.action == "edit") {
            jv.$router.push("/system/sso-config/list")
        }
    })
};

onMounted( function() {
    loadData();
} )



</script>
